package com.demo5;

public class PhoneTest {
    public static void main(String[] args) {
        //1.创建一个数组
        Phone[] arr = new Phone[3];
        //2.创建手机的对象
        Phone phone1 = new Phone("小米", 1999, "红色");
        Phone phone2 = new Phone("华为", 4999, "蓝色");
        Phone phone3 = new Phone("魅族", 2999, "黑色");

        //3.把手机对象添加到数组中
        arr[0] = phone1;
        arr[1] = phone2;
        arr[2] = phone3;

        //4.获取三部手机的平均价格
        int sum = 0;
        for (int i = 0; i < arr.length; i++) {
            //i 索引 arr[i] 元素
            Phone phone = arr[i];
            sum += phone.getPrice();
        }

        //5.求平均值
        double avg = sum * 1.0 / arr.length;
        System.out.println("avg=" + avg);
    }
}
